package com.ruoyi.residentsqr.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.ruoyi.pojo.TbResidents;
import com.ruoyi.residentsqr.mapper.TbResidentsMapper;
import com.ruoyi.residentsqr.residentqrDto.ResidentsDto;
import com.ruoyi.residentsqr.residentsqrVo.ResidentsVo;
import com.ruoyi.residentsqr.service.TbResidentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TbResidentsServiceImpl extends ServiceImpl<TbResidentsMapper, TbResidents> implements TbResidentsService {

    @Autowired
    private TbResidentsMapper tbResidentsMapper;


    @Override
    public Page<ResidentsVo> findPage(ResidentsDto residentsDto) {
        Page<TbResidents> page = new Page<>(residentsDto.getPageNum(), residentsDto.getPageSize());
        return tbResidentsMapper.findPage(page,residentsDto);
    }

    @Override
    public ResidentsVo getId(Integer id) {
        return tbResidentsMapper.getId(id);
    }

    @Override
    public void updateresidentsqr(ResidentsVo residentsVo) {
        //利用请求携带的审核id查到对应的住户
        TbResidents tbResidents = tbResidentsMapper.selectById(residentsVo.getId());
        tbResidents.setAccessExpirationDate(residentsVo.getAccessExpirationDate());
        tbResidents.setAuditStatus(residentsVo.getAuditStatus());
        if(tbResidents.getAuditStatus()==1 &&residentsVo.getResidentsAccessId()!=null){
            tbResidents.setResidentsAccessId(residentsVo.getResidentsAccessId());
        }
        if(tbResidents.getAuditStatus()==3 &&residentsVo.getRejectReason()!=null){
            tbResidents.setRejectReason(residentsVo.getRejectReason());
        }
        tbResidentsMapper.updateById(tbResidents);
    }


}
